package com.chinaoly.sdk.data;



import com.chinaoly.sdk.constant.ResConstants;
import com.chinaoly.sdk.data.entity.BaseResult;

import io.reactivex.functions.Consumer;

/**
 * Created by chenjian on 2019/6/13 16:53.
 */
public class NormalConsumer<T> implements Consumer<BaseResult<T>> {
    public NormalConsumer(DataCallBackListener<BaseResult<T>> l) {
        this.l = l;
    }

    private final DataCallBackListener<BaseResult<T>> l;
    @Override
    public void accept(BaseResult<T> t) throws Exception {
        if (t == null) {
            l.onDataNotAvailable(ResConstants.GET_DATA_FAIL);
            return;
        }
        if(ResConstants.RES_OK == t.code){
            l.onDataLoaded(t);
        }else{
            l.onDataNotAvailable(t.message);
        }
    }
}
